package com.xuanyuan.controller;

import com.xuanyuan.domain.AjaxResult;
import com.xuanyuan.entity.DictData;
import com.xuanyuan.service.DictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

@Validated
@Controller
@RequestMapping("/api/dict")
public class DictController {
    @Autowired
    private DictDataService dictDataService;

    @ResponseBody
    @RequestMapping("/getDictDataByType")
    public AjaxResult selectDictDataByType(@NotBlank(message = "字典类型不能为空") String dictType) {
        List<DictData> data = dictDataService.selectDictDataByType(dictType);
        if (data == null) {
            data = new ArrayList<>();
        }
        return AjaxResult.success(data);
    }
}

